var ClubRoomManagerTab = Item.extend({
    _ccsFileName: res.ClubRoomManagerTab_json,
    _clubId: 0,
    _originalList: [],
    _roomList: [],

    initItem: function (clubId) {
        this._clubId = clubId;

        this.initTableView();

    },
    onEnter: function () {
        Item.prototype.onEnter.call(this);
        this._addClickListeners();
    },
    _initClickListeners: function () {
        this._clickListeners = {
            'node_select.btn_find': '_clickFind',
        }
    },


    /**
     * 发送当前界面 需要请求的数据消息
     */
    sendMsg:function(){
        network.send(2103, {cmd: ClubMsgCode.ListClubRoom, club_id: this._clubId, reason: 'flushClub'});
    },


    /**
     * 点击查找
     * @private
     */
    _clickFind: function () {
        var inputNode = this._nodeList['node_select.input'];
        inputNode.didNotSelectSelf();
        var input = inputNode.getString();

        var findRoom = [];
        for (var i = 0; i < this._originalList.length; i++) {
            var data = this._originalList[i];
            if (data['room_id'].toString().indexOf(input) >= 0) {
                findRoom.push(data);
            }
        }
        if (findRoom.length > 0) {
            this._roomList = findRoom;
        } else {
            this._roomList = this._originalList;
        }
        this._tableView.reloadData();
    },

    refreshView: function (clubId) {
        this._clubId = clubId;
        var club = ClubDataManager.getClubData(clubId);
        this._roomList = club.createRoomList || [];
        this._originalList = club.createRoomList || [];
        if (this._roomList == undefined || this._roomList.length == 0) {
            this._nodeList['node_rooms.tips'].setVisible(true);
        } else {
            this._nodeList['node_rooms.tips'].setVisible(false);
        }
        this._tableView.reloadData();
    },

    /**
     * 初始化TableView
     */
    initTableView: function () {
        var nodeContent = this._nodeList['nodeContent'];
        var tableViewSize = nodeContent.getContentSize();
        this._tableView = new cc.TableView(this, cc.size(tableViewSize.width, tableViewSize.height));
        this._tableView.setDelegate(this);
        this._tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        this._tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        this._tableView.setPosition(nodeContent.getPosition());
        nodeContent.getParent().addChild(this._tableView);
    },

    tableCellAtIndex: function (table, idx) {
        var cell = table.dequeueCell();
        var node = null;
        if (cell == null) {
            cell = new cc.TableViewCell();
            node = addItem('ClubRoomItem', cell, this._clubId, this._roomList[idx]);
            node.setName("itemCell");
        } else {
            node = cell.getChildByName("itemCell");
            node.setData(this._clubId, this._roomList[idx]);
        }
        return cell;
    },
    tableCellTouched: function (table, cell) {

    },
    tableCellSizeForIndex: function (table, idx) {
        return cc.size(1150, 86);
    },
    numberOfCellsInTableView: function (table) {
        return this._roomList.length;
    },
});